package com.crazy.base.common.utils.configuration;

import com.crazy.base.common.utils.id.SnowflakeGenerator;
import com.crazy.base.common.utils.id.SnowflakeProperties;
import com.crazy.base.common.utils.id.UidGenerator;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
public class UidGeneratorAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean(UidGenerator.class)
    public SnowflakeGenerator snowflakeGenerator(SnowflakeProperties snowflakeProperties) {
        return new SnowflakeGenerator(snowflakeProperties.getWorkId(), snowflakeProperties.getDataCenterId());
    }
}
